<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>质检总表显示页面</title>
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<style type="text/css">
body {
	margin: 20px 0px;
}
 body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
    .demoTable{
    	z-index: 10px;
    }
</style>
</head>
<body>
	<div class="demoTable">
		时间：
		<div class="layui-input-inline">
			<input name="date" id="date" lay-verify="date"
				placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input"
				type="text">
		</div>
		——
		<div class="layui-input-inline">
			<input name="date" id="date1" lay-verify="date"
				placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input"
				type="text">
		</div>
		<button class="layui-btn" data-type="reload">搜索</button>

	<table class="layui-hide" id="qtSumModel" lay-filter="demo"></table>
</div>

	<script type="text/html" id="barDemo">
{{# if(d.sumRate == 0){ }}  
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">质检质检表</a>
{{# }else{ }}
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看质检表</a>
  	<a class="layui-btn layui-btn-xs" lay-event="rk" id="rk">入库</a>
{{# }}}
</script>
	<script type="text/javascript" src="../../res/js/base.js"></script>
	<script src="../../layui/layui.js"></script>
<script>

layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element; //元素操作
	 
	  
	  //日期
	  laydate.render({
		    elem: '#date',
		    type:'datetime'
	  });
	  laydate.render({
		    elem: '#date1',
		    type:'datetime'
	  });
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#qtSumModel'
	    ,width:1000
	    ,height: 500
	    ,url: getRootPath()+'qtSumModel/findAllQtSumModel.action' //数据接口
	    ,page: true //开启分页
	    ,method:'post'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'sumId', title: '质检总报表ID', width:120, fixed: 'left'}
	      ,{field: 'poId', title: '采购订单ID', width:120}
	      ,{field: 'sumNopass', title: '质检总未通过数', width:120}
	      ,{field: 'sumSumnum', title: '质检总数', width:120}
	      ,{field: 'sumRate', title: '质检总通过率', width: 120}
	  <!--,{field: 'sumRemark', title: '质检总备注', width: 120}-->
	  <!--,{field: 'isva', title: '是否有效', width: 120}-->
	  <!--,{field: 'sumPerson', title: '质检总报表人', width: 120}-->
	  <!--,{field: 'sort', title: '排序', width: 120}-->
	      ,{field: 'sumTimes', title: '质检总报表时间', width: 120}
	  	  ,{field: 'filId', title: '分公司ID', width: 120}
	      ,{fixed: 'right',title: '操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	  //监听工具条
	  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'rk'){
	    	 
	    	 
	    	 var sumId=data.sumId;
	    	 var filId=data.filId;
	    	 var sumNopass=data.sumNopass;
	    	 var sumSumnum=data.sumSumnum;
	    	 var poId=data.poId;
	    	 
	    	 layer.confirm('确认入库?', function(index){
	    	 layer.close(index);
		      
		      //使用jquery的ajax方式向后台提交数据
			  var url = "../../Repertory/insertById.action";
			  
		 	  var data = {sumId:sumId,filId:filId,sumNopass:sumNopass,sumSumnum:sumSumnum,poId:poId};
			  $.post(url,data,function(data){
				  
					 if(data =="ok"){
						 
						layer.msg('入库成功', {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								
							  location.reload(); // 页面刷新
								 
						});
						$("#rk").text("已入库");
					}else {
						layer.msg('入库失败',{
								icon:2,
								time: 1000
							},function(){
								location.reload();
						})
					}
					  

				});
	    }); 
	      
	      
	    } else if(layEvent === 'detail'){
	    	var sumId=data.sumId;
			var sumNopass = data.sumNopass;
	    	
	    	
   	    	layer.open({
   	 			  type: 2,
   	 			  area : ['76%' , '75%'],//弹出框大小
   	 			  shift:1,//弹出框动画效果
   	 			  content: 'QualityTestingModelShowList.html?sumNopass='+sumNopass+"&sumId="+sumId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
	   	 	});
		}
	  });
	  
	  
	  
	  

	//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			//var demoReload = $('#demoReload');
			//alert($("#date").val());
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					//sellName : demoReload.val(),
					dateOne: $("#date").val(),
					dateTwo: $("#date1").val()
				}
				
			});
		});
});
			  
	/*  $('#qtSumModelAdd').on('click', function(){
		 layer.open({
			  type: 	2,
			  area : ['60%' , '80%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: ['QtSumModelAdd.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			}); 
	   }); 
	  
	});*/
	  
	  
</script>


</body>
</html>